class_name ControllerComponent_Motion_Linear
extends ControllerComponent_Motion

#region 属性
@export var is_speed_update:bool = false
@export_group("线性速度")
@export var acc:float = 0
@export var is_limited_speed:bool = false
@export var limited_speed:float
@export_group("旋转速度")
@export var rotate_angle_speed:float = 0
@export var rotate_angle_acc:float = 0
@export var is_limited_rotate_angle_speed:bool = false
@export var limited_rotate_angle_speed:float
@export_group("是否朝向速度方向")
@export var is_face_vel_dir:bool = false
@export_group("是否随着移动方向翻转")
@export var is_can_flip:bool = false
@export_group("重力相关")
@export var is_simulate_gravity:bool = false
@export var gravity_acc:float = 9.8
@export_group("")

var speed_inited:bool = false
var cur_rotate_angle_speed = 0
var cur_speed:float = 0
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 虚方法（子类必须实现）
#endregion
#region 基类方法
func update_vel(delta):
	if not speed_inited:
		speed_inited = true
		cur_speed = entity.entity_data.get_attribute_value("MaxMoveSpeed")
		cur_rotate_angle_speed = rotate_angle_speed
		target_vel = Vector2(1,0).rotated(entity.root.transform.get_rotation()) * cur_speed
		target_angular_vel = deg_to_rad(cur_rotate_angle_speed)
	else:
		if not is_speed_update:
			pass
		else:
			if abs(acc) > 0:
				cur_speed += acc * delta
			if is_limited_speed:
				cur_speed = clamp(cur_speed,min(entity.entity_data.move_speed_property_data.get_modified_property(),limited_speed),max(entity.entity_data.move_speed_property_data.get_modified_property(),limited_speed))
			if abs(rotate_angle_acc) > 0:
				cur_rotate_angle_speed += rotate_angle_acc * delta
			if is_limited_rotate_angle_speed:
				cur_rotate_angle_speed = clamp(cur_rotate_angle_speed,min(rotate_angle_speed,limited_rotate_angle_speed),max(rotate_angle_speed,limited_rotate_angle_speed))
			target_angular_vel = deg_to_rad(cur_rotate_angle_speed)
			if is_face_vel_dir:
				target_vel = Vector2(1,0).rotated(entity.root.transform.get_rotation()) * cur_speed
			else:
				target_vel = Vector2(1,0).rotated(target_vel.angle()) * cur_speed
			if is_simulate_gravity:
				target_vel += Vector2(0, gravity_acc) * delta;
func get_target_vel(delta:float) -> Vector2:
	return super(delta)
func get_target_angular_vel(delta:float) -> float:
	return super(delta)
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
